#include "coin.h"

Coin::Coin(int v, sf::Vector2f pos, sf::Vector2f scale){
    //set up texture
    texture.loadFromFile("resources/coins.png");
    sprite.setTexture(texture);
    //scale the sprite to 'scale'
    sprite.setScale(scale);
    value = v;
    switch(v){
    case 1:
        //penny
        sprite.setTextureRect(sf::IntRect(288,0,96,96));
        break;
    case 5:
        //nickel
        sprite.setTextureRect(sf::IntRect(192,0,96,96));
        break;
    case 10:
        sprite.setTextureRect(sf::IntRect(96,0,96,96));
        break;
    case 25:
        sprite.setTextureRect(sf::IntRect(0,0,96,96));
        break;
    default:
        break;
    }
    //set the middle of the coin to pos
    sprite.setPosition(pos.x - sprite.getGlobalBounds().width /2, pos.y - sprite.getGlobalBounds().height /2);
}

//Return the value of a given coin
int Coin::getValue(){
    return value;
}

// Returns true if the point is inside the sprite rect
bool Coin::isClicked(sf::Vector2f vec){
    if (sprite.getGlobalBounds().contains(vec)){
        return true;
    }else return false;
}
